using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyControl : MonoBehaviour, IAttack
{
    [Header("巡逻")]
    [SerializeField] private Transform left;
    public Transform GetLeft
    {
        get { return left; }
    }
    [SerializeField] private Transform right;
    public Transform GetRight
    {
        get { return right; }
    }
    [Header("组件")]
    // 组件
    [SerializeField] private Rigidbody2D rb;
    public Rigidbody2D GetRb
    {
        get { return rb; }
    }
    [SerializeField] private Animator animator;
    public Animator GetAnimator
    {
        get { return animator; }
    }

    [SerializeField] private BoxCollider2D mineBox2D;
    public BoxCollider2D GetMineBox2D
    {
        get { return mineBox2D; }
    }
    [SerializeField] private GameObject foot;
    public GameObject GetFoot
    {
        get { return foot; }
    }
    
    [Header("变量")]
    [SerializeField] private float enemyMoveSpeed;             // 小怪移动速度
    public float GetEnemyMoveSpeed
    {
        get { return enemyMoveSpeed; }
    }
    public bool IsHit { get; set; }                            // 小怪是否受伤
    
    
    //
    void Start()
    {
        IsHit = false;
        rb = GetComponent<Rigidbody2D>();
        mineBox2D = GetComponent<BoxCollider2D>();
    }
    
    /// <summary>
    /// 设置朝向
    /// </summary>
    /// <param name="dir">朝向</param>
    public void SetLocalScale(int dir)
    {
        this.gameObject.transform.localScale = new Vector3(dir, this.gameObject.transform.localScale.y,
            this.gameObject.transform.localScale.z);
    }

    //
    public void Attack()
    {
        IsHit = true;
    }
    
    //
    private void OnTriggerEnter2D(Collider2D other)
    {
        if(other == null)
            return;
        if (other.CompareTag("Player"))
        {
            IAttack attack = other.gameObject.GetComponent<IAttack>();
            attack.Attack();
        }
    }
}
